import { makeRequiredRule } from '../../../utils'

const label = '图片'
const name = 'upload'
let i = 1
const uniqueId = () => `${name}${i++}`

export default {
  label,
  name,
  rule() {
    return {
      type: name,
      field: uniqueId(),
      title: label,
      value: [],
      props: {
        action: 'https://match.zh24.shop/common/upload/oss',
        multiple: false,
        uploadType: 'image',
        onSuccess(res, file) {
          if (res.code === 0) {
            file.url = res.data.url
          }
        }
      }
    }
  },
  props() {
    return [
      {
        type: 'input',
        field: 'formCreateTitle',
        value: label,
        title: '字段名称'
      },
      makeRequiredRule(),
      {
        type: 'select',
        field: 'uploadType',
        title: '上传类型',
        value: 'image',
        options: [
          { label: '图片', value: 'image' },
          {
            label: '文件',
            value: 'file'
          }
        ]
      },
      {
        type: 'inputNumber',
        field: 'limit',
        title: '最大允许上传个数'
      }
    ]
  }
}
